
import 'package:containerbox_study/BottomBar/app.dart';
import 'package:containerbox_study/page/toutiao/toutiao_detail.dart';
import 'package:containerbox_study/app_login_page.dart';
import 'package:containerbox_study/routers/permission_router.dart';
import 'package:containerbox_study/routers/router_nullpage.dart';
import 'package:containerbox_study/splash/splash_page.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';


/*
// 自定义的路由表
class RouterTable{
  static String splashPath = 'splash';
  static String loginPath = 'login';
  static String noPagePath = '404';
  static String homePath = 'home';
  static String articleDetailPath = 'articleDetail';

  //路由表
  static Map<String, WidgetBuilder> routerTables = {
    splashPath: (context) => SplashPage(),
    loginPath: (context) => LoginPage(),
    homePath: (context) =>AppHomePage(),
    noPagePath: (context) => NoFindPage(),
    articleDetailPath: (context) => ToutiaoArticleDetail(),
  };


  //路由拦截器
  static Route onGenerateRoute<T extends Object>(RouteSettings settings){
    return CupertinoPageRoute<T> (
      settings: settings,
      builder: (context) {
        String name = settings.name.toString();
        if (routerTables[name] == null){
          name = noPagePath;
        }
        Widget widget = routerTables[name]!(context);
        return widget;
      },
    );
  }
}
*/

//使用第三方路由插件
class RouterManager{
  
 static String splashPath = '/';
 static String loginPath = '/login';
 static String noPagePath = '/404';
 static String permissionDefinePath = '/403';
 static String homePath = '/home';
 static String articleDetailPath = '/articleDetail';
 static String dynamicDetailPath = '$articleDetailPath/:title';


  static PermissionRouter? router;
  
  static void initRouter({required List<String> whiteList}){
    if (router == null) {
      router = PermissionRouter();
      defineRoutes(whiteList);
    }
  }

  static final routerTable = {
    loginPath : Handler(handlerFunc: (BuildContext? context, Map<String, dynamic> params) => LoginPage()),
    splashPath :  Handler(handlerFunc: (BuildContext? context, Map<String, dynamic> params) => SplashPage()),
    homePath : Handler(handlerFunc: (BuildContext? context, Map<String, dynamic> params) => AppHomePage()),
    dynamicDetailPath : Handler(handlerFunc: (BuildContext? context, Map<String, dynamic> params) => 
  ToutiaoArticleDetail((params['title'][0]))),
  };

  static void defineRoutes(List<String> whiteList) {
    router!.whiteList = whiteList;
    router!.permissionDefinePath = permissionDefinePath;
    routerTable.forEach((key, handler) {
      router!.define(key, handler: handler, transitionType: TransitionType.native, transitionDuration: Duration(milliseconds: 100));
    });
    router!.notFoundHandler = Handler(
      handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
        return NoFindPage();
      });
    // router!.define(splashPath, handler: splashHandler);
    // router!.define(homePath, handler: homeHandler);
    // router!.define(loginPath, handler: loginHandler, transitionType: TransitionType.inFromRight);
    // router!.define(dynamicDetailPath, handler: dynamicDetailHandler, transitionType: TransitionType.none);
    // router!.notFoundHandler = notFoundHandler;
  }


/*
  static var splashHandler = Handler(handlerFunc: (BuildContext? context, Map<String, dynamic> params) => SplashPage());
  static var homeHandler = Handler(handlerFunc: (BuildContext? context, Map<String, dynamic> params) => AppHomePage());
  static var loginHandler = Handler(handlerFunc: (BuildContext? context, Map<String, dynamic> params) => LoginPage());
  static var notFoundHandler = Handler(handlerFunc: (BuildContext? context, Map<String, dynamic> params) => NoFindPage());
  static var dynamicDetailHandler = Handler(handlerFunc: (BuildContext? context, Map<String, dynamic> params) => 
  ToutiaoArticleDetail((params['title'][0])));
*/


}